#!/bin/sh

# If $1 is a mountpoint, return it; else if it is a mounted device,
# return the mountpoint for the device; else return eror.
#
# value returned in global $mountpoint.
get_mountpoint() {
    if mountpoint -q -- $1; then
        mountpoint=$1
        return 0
    fi

    mountpoint=$(grep "^$1" /proc/mounts | cut -d' ' -f2)

    if [ -n "$mountpoint" ]; then
        return 0
    fi

    return 1
}

for arg in $@; do
    if get_mountpoint $arg; then
        # Please keep in sync with mount script, which starts these processes.
        squashed_mountpoint=$(echo ${mountpoint} | sed 's^/^_^g')
        statsbase="${TMPDIR:-/tmp}/nfusr_client${squashed_mountpoint}"
        logfile="${statsbase}.log"
        statsfile="${statsbase}.stats"
        pkill -f "gfs_clientstats_scuba.*$logfile"
        pkill -f "gfs_clientstats_ods.*$statsfile"
     fi
done

umount -i $@
